<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  data() {
    return {
      appWindow: window,
      form: {
        number: "",
      },
      showDialog: false,

      isloading: false,
      usersIds: [],

      apiUrl: {
        handOut: "api/coupon/batchMemberCoupon",
      },
    };
  },
  methods: {
    // 关闭
    handleClose(done) {
      this.showDialog = false;
    },

    // 点击取消
    cancelDialog() {
      this.showDialog = false;
    },

    // 点击确定 发送请求
    async submit() {},

    init() {
      this.showDialog = true;
    },

    // 回调
    onSuccess() {},

    // 点击选择客户发放优惠券
    chooseUsers() {
      this.$vFN.Directives.SelectDataUsers({
        appWindow: this.appWindow,
        selectIds: this.usersIds,
        count: -1,
        apiConfig: this.$vFN.Tools.getAppGlobalData(
          "componentsApiConfig.SelectDataUsers",
          this.appWindow
        ),
        onSuccess: (res) => {
          // 返回客户数组
          console.log(res, "res");
          this.usersIds = res;
          console.log(this.usersIds);
        },
      });
    },

    async handOutCoupon() {
      if (this.form.number == "") {
        this.$vFN.Tools.messageError("请填写发放数量");
        return;
      }

      if (this.$vFN.Utils.isEmpty(this.usersIds)) {
        this.$vFN.Tools.messageError("请选择发放的客户");
        return;
      }

      this.couponList.forEach((item) => {
        item.number = this.form.number;
      });
      this.isloading = true;
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.handOut,
          data: {
            couponList: this.couponList,
            memberIds: this.usersIds,
          },
        },
        window
      );
      this.isloading = false;
      if (res._ok) {
        console.log(res);
        this.$vFN.Tools.messageSuccess(res.message);
        this.showDialog = false;
        this.onSuccess();
      }
    },
  },
  mounted() {
    this.init();
  },
};
</script>
